﻿using Bll;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Model;

namespace Store_API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class StoreController : ControllerBase
    {
        private readonly storeBll bll;

        public StoreController(storeBll bll)
        {
            this.bll = bll;
        }

        /// <summary>
        /// 门店增加
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult PostAddStore(T_StoreInfo info)
        {
            try
            {
                int res = bll.PostAddStore(info);
                return Ok(new
                {
                    data = res
                });
            }
            catch (Exception)
            {
                throw;
            }
        }


        /// <summary>
        /// 显示数据查询
        /// </summary>
        /// <param name="name">门店名称</param>
        /// <param name="phone">门店电话</param>
        /// <param name="indexs">总页数</param>
        /// <param name="counts">总条数</param>
        /// <param name="pageIndex">当前页</param>
        /// <param name="pageSize">每页显示几条</param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetStoreList(string? name, string? phone,  int pageIndex = 1, int pageSize = 2)
        {
            try
            {
                int counts = 0;
                int indexs = 0;
                var list = bll.GetStoreList(name, phone, out indexs, out counts, pageIndex, pageSize);
                return Ok(new
                {
                    data = list,
                    counts = counts,
                    indexs = indexs
                });
            }
            catch (Exception)
            {
                throw;
            }
        }

        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetDeleteInfo(int id)
        {
            try
            {
                int res = bll.GetDeleteInfo(id);
                return Ok(new
                {
                    data = res
                });
            }
            catch (Exception)
            {
                throw;
            }
        }

        /// <summary>
        /// 优惠券添加
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult PostDiscountAdd(T_Discount info)
        {
            try
            {
                int res = bll.PostDiscountAdd(info);
                return Ok(new
                {
                    data = res
                });
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}
